<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Voya Media: FileSystem.cs Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Voya Media
   &#160;<span id="projectnumber">1.2.255.1212</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00014.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">FileSystem.cs</div>  </div>
</div><!--header-->
<div class="contents">
<a href="a00014.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 ﻿using System;
<a name="l00002"></a>00002 <span class="keyword">using</span> System.IO;
<a name="l00003"></a>00003 <span class="keyword">using</span> System.Collections;
<a name="l00004"></a>00004 <span class="keyword">using</span> System.Collections.Generic;
<a name="l00005"></a>00005 <span class="keyword">using</span> System.Diagnostics;
<a name="l00006"></a>00006 <span class="keyword">using</span> System.Security.AccessControl;
<a name="l00007"></a>00007 <span class="keyword">using</span> System.Security.Permissions;
<a name="l00008"></a>00008 <span class="keyword">using</span> System.Text;
<a name="l00009"></a>00009 <span class="keyword">using</span> System.Text.RegularExpressions;
<a name="l00010"></a>00010 <span class="keyword">using</span> System.Threading;
<a name="l00011"></a>00011 
<a name="l00012"></a><a class="code" href="a00025.html">00012</a> <span class="keyword">namespace </span>FileSystem
<a name="l00013"></a>00013 {
<a name="l00017"></a><a class="code" href="a00003.html">00017</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>
<a name="l00018"></a>00018     {
<a name="l00019"></a>00019         <span class="comment">// Define private member properties.</span>
<a name="l00020"></a>00020         <span class="keyword">private</span> <span class="keyword">static</span> List&lt;string&gt; filesInDirectory = <span class="keyword">new</span> List&lt;string&gt;();
<a name="l00021"></a>00021 
<a name="l00031"></a><a class="code" href="a00003.html#a8268e86a251fc815f8729e5f41d9ca37">00031</a>         <span class="keyword">public</span> <span class="keyword">static</span> List&lt;string&gt; <a class="code" href="a00003.html#a8268e86a251fc815f8729e5f41d9ca37" title="Replaces the default System.IO.Directory.GetFiles() method with Recursive option since it throws Syst...">GetAllFilesInDirectory</a>(<span class="keywordtype">string</span> directoryPath, <span class="keywordtype">int</span> maxFiles = 1000000)
<a name="l00032"></a>00032         {
<a name="l00033"></a>00033             <span class="comment">// Clear/Empty the list before starting.</span>
<a name="l00034"></a>00034             <a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>.filesInDirectory.Clear();
<a name="l00035"></a>00035 
<a name="l00036"></a>00036             <span class="comment">// Use the internal helper method to get all files in the directory.</span>
<a name="l00037"></a>00037             <a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>.GetAllFilesInDirectoryInternal(directoryPath, maxFiles);
<a name="l00038"></a>00038 
<a name="l00039"></a>00039             <span class="comment">// After adding files from the directory and all sub directories, </span>
<a name="l00040"></a>00040             <span class="comment">// return the list of files.</span>
<a name="l00041"></a>00041             <span class="keywordflow">return</span> <a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>.filesInDirectory;
<a name="l00042"></a>00042         }
<a name="l00043"></a>00043 
<a name="l00052"></a>00052         <span class="keyword">private</span> <span class="keyword">static</span> <span class="keywordtype">void</span> GetAllFilesInDirectoryInternal(<span class="keywordtype">string</span> directoryPath, <span class="keywordtype">int</span> maxFiles)
<a name="l00053"></a>00053         {
<a name="l00054"></a>00054             <span class="comment">// Get the filesystem and security properties of the root directory.</span>
<a name="l00055"></a>00055             DirectoryInfo     directoryInfo        = <span class="keyword">new</span> DirectoryInfo(directoryPath);
<a name="l00056"></a>00056             DirectorySecurity directoryPermissions = <span class="keyword">new</span> DirectorySecurity();
<a name="l00057"></a>00057 
<a name="l00058"></a>00058             <span class="keywordflow">try</span>
<a name="l00059"></a>00059             {
<a name="l00060"></a>00060                 <span class="comment">// 1. This first part will get a list of all the files in the root directory.</span>
<a name="l00061"></a>00061 
<a name="l00062"></a>00062                 <span class="comment">// Check if the root directory is accessible.</span>
<a name="l00063"></a>00063                 directoryPermissions = Directory.GetAccessControl(directoryPath);
<a name="l00064"></a>00064 
<a name="l00065"></a>00065                 <span class="comment">// Check if the root directory is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00066"></a>00066                 <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00067"></a>00067                 {
<a name="l00068"></a>00068                     <span class="comment">// Get a list of all files in the root directory.</span>
<a name="l00069"></a>00069                     <span class="keywordtype">string</span>[] rootFiles = Directory.GetFiles(directoryPath, <span class="stringliteral">&quot;*&quot;</span>, SearchOption.TopDirectoryOnly);
<a name="l00070"></a>00070 
<a name="l00071"></a>00071                     <span class="comment">// Check each file.</span>
<a name="l00072"></a>00072                     <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> file <span class="keywordflow">in</span> rootFiles)
<a name="l00073"></a>00073                     {
<a name="l00074"></a>00074                         <span class="comment">// Get the filesystem and security properties of the root files.</span>
<a name="l00075"></a>00075                         FileInfo     fileInfo        = <span class="keyword">new</span> FileInfo(file);
<a name="l00076"></a>00076                         FileSecurity filePermissions = <span class="keyword">new</span> FileSecurity();
<a name="l00077"></a>00077 
<a name="l00078"></a>00078                         <span class="keywordflow">if</span> (<a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>.filesInDirectory.Count &lt; maxFiles)
<a name="l00079"></a>00079                         {
<a name="l00080"></a>00080                             <span class="keywordflow">try</span>
<a name="l00081"></a>00081                             {
<a name="l00082"></a>00082                                 <span class="comment">// Check if the root file is accessible.</span>
<a name="l00083"></a>00083                                 filePermissions = File.GetAccessControl(file);
<a name="l00084"></a>00084 
<a name="l00085"></a>00085                                 <span class="comment">// Check if the file is a real file or if it is a Junction/Reparse point.</span>
<a name="l00086"></a>00086                                 <span class="keywordflow">if</span> ((fileInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00087"></a>00087                                 {
<a name="l00088"></a>00088                                     <span class="comment">// Add the file to the final list of files we will return.</span>
<a name="l00089"></a>00089                                     <a class="code" href="a00003.html" title="Custom methods for File Operations.">FileManagement</a>.filesInDirectory.Add(fileInfo.FullName);
<a name="l00090"></a>00090                                 }
<a name="l00091"></a>00091                             }
<a name="l00092"></a>00092                             <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00093"></a>00093                             {
<a name="l00094"></a>00094                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00095"></a>00095                             }
<a name="l00096"></a>00096                             <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00097"></a>00097                             {
<a name="l00098"></a>00098                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00099"></a>00099                             }
<a name="l00100"></a>00100                             <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00101"></a>00101                             {
<a name="l00102"></a>00102                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00103"></a>00103                             }
<a name="l00104"></a>00104                             <span class="keywordflow">catch</span> (Exception)
<a name="l00105"></a>00105                             {
<a name="l00106"></a>00106                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00107"></a>00107                             }
<a name="l00108"></a>00108                         }
<a name="l00109"></a>00109                     }
<a name="l00110"></a>00110                 }
<a name="l00111"></a>00111 
<a name="l00112"></a>00112                 <span class="comment">// 2. This second part will get a list of all sub directories in the root directory.</span>
<a name="l00113"></a>00113 
<a name="l00114"></a>00114                 <span class="keywordflow">try</span>
<a name="l00115"></a>00115                 {
<a name="l00116"></a>00116                     <span class="comment">// Check if the root directory is accessible.</span>
<a name="l00117"></a>00117                     directoryPermissions = Directory.GetAccessControl(directoryPath);
<a name="l00118"></a>00118 
<a name="l00119"></a>00119                     <span class="comment">// Check if the folder is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00120"></a>00120                     <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00121"></a>00121                     {
<a name="l00122"></a>00122                         <span class="comment">// Get a list of all sub directories in the root directory.</span>
<a name="l00123"></a>00123                         <span class="keywordtype">string</span>[] subDirectories = Directory.GetDirectories(directoryPath, <span class="stringliteral">&quot;*&quot;</span>, SearchOption.TopDirectoryOnly);
<a name="l00124"></a>00124 
<a name="l00125"></a>00125                         <span class="comment">// Check each sub directory.</span>
<a name="l00126"></a>00126                         <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> subDirectory <span class="keywordflow">in</span> subDirectories)
<a name="l00127"></a>00127                         {
<a name="l00128"></a>00128                             <span class="comment">// Get the filesystem and security properties of the sub directories.</span>
<a name="l00129"></a>00129                             DirectoryInfo     subDirectoryInfo        = <span class="keyword">new</span> DirectoryInfo(subDirectory);
<a name="l00130"></a>00130                             DirectorySecurity subDirectoryPermissions = <span class="keyword">new</span> DirectorySecurity();
<a name="l00131"></a>00131 
<a name="l00132"></a>00132                             <span class="keywordflow">try</span>
<a name="l00133"></a>00133                             {
<a name="l00134"></a>00134                                 <span class="comment">// Check if the sub directories are accessible.</span>
<a name="l00135"></a>00135                                 subDirectoryPermissions = Directory.GetAccessControl(subDirectory);
<a name="l00136"></a>00136 
<a name="l00137"></a>00137                                 <span class="comment">// Check if the folder is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00138"></a>00138                                 <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00139"></a>00139                                 {
<a name="l00140"></a>00140                                     <span class="comment">// Recursively check files in each sub directory.</span>
<a name="l00141"></a>00141                                     FileManagement.GetAllFilesInDirectoryInternal(subDirectory, maxFiles);
<a name="l00142"></a>00142                                 }
<a name="l00143"></a>00143                             }
<a name="l00144"></a>00144                             <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00145"></a>00145                             {
<a name="l00146"></a>00146                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00147"></a>00147                             }
<a name="l00148"></a>00148                             <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00149"></a>00149                             {
<a name="l00150"></a>00150                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00151"></a>00151                             }
<a name="l00152"></a>00152                             <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00153"></a>00153                             {
<a name="l00154"></a>00154                                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00155"></a>00155                             }
<a name="l00156"></a>00156                         }
<a name="l00157"></a>00157                     }
<a name="l00158"></a>00158                 }
<a name="l00159"></a>00159                 <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00160"></a>00160                 {
<a name="l00161"></a>00161                     <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00162"></a>00162                 }
<a name="l00163"></a>00163                 <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00164"></a>00164                 {
<a name="l00165"></a>00165                     <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00166"></a>00166                 }
<a name="l00167"></a>00167                 <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00168"></a>00168                 {
<a name="l00169"></a>00169                     <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00170"></a>00170                 }
<a name="l00171"></a>00171             }
<a name="l00172"></a>00172             <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00173"></a>00173             {
<a name="l00174"></a>00174                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00175"></a>00175             }
<a name="l00176"></a>00176             <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00177"></a>00177             {
<a name="l00178"></a>00178                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00179"></a>00179             }
<a name="l00180"></a>00180             <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00181"></a>00181             {
<a name="l00182"></a>00182                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00183"></a>00183             }
<a name="l00184"></a>00184             <span class="keywordflow">catch</span> (IOException)
<a name="l00185"></a>00185             {
<a name="l00186"></a>00186                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00187"></a>00187             }
<a name="l00188"></a>00188             <span class="keywordflow">catch</span> (Exception)
<a name="l00189"></a>00189             {
<a name="l00190"></a>00190                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00191"></a>00191             }
<a name="l00192"></a>00192         }
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194 
<a name="l00198"></a><a class="code" href="a00002.html">00198</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>
<a name="l00199"></a>00199     {
<a name="l00200"></a>00200         <span class="comment">// Define private member properties.</span>
<a name="l00201"></a>00201         <span class="keyword">private</span> <span class="keyword">static</span> List&lt;string&gt; subDirectoriesInDirectory = <span class="keyword">new</span> List&lt;string&gt;();
<a name="l00202"></a>00202 
<a name="l00212"></a><a class="code" href="a00002.html#a1799b4c602786a8468e3a79db8cbabdb">00212</a>         <span class="keyword">public</span> <span class="keyword">static</span> List&lt;string&gt; <a class="code" href="a00002.html#a1799b4c602786a8468e3a79db8cbabdb" title="Replaces the default System.IO.Directory.GetDirectories() method with Recursive option since it throw...">GetAllSubDirectoriesInDirectory</a>(<span class="keywordtype">string</span> directoryPath, <span class="keywordtype">int</span> maxSubDirectories = 1000000)
<a name="l00213"></a>00213         {
<a name="l00214"></a>00214             <span class="comment">// Clear/Empty the list before starting.</span>
<a name="l00215"></a>00215             <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.subDirectoriesInDirectory.Clear();
<a name="l00216"></a>00216 
<a name="l00217"></a>00217             <span class="comment">// Use the internal helper method to get all sub-directories in the directory.</span>
<a name="l00218"></a>00218             <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.GetAllSubDirectoriesInDirectoryInternal(directoryPath, maxSubDirectories);
<a name="l00219"></a>00219 
<a name="l00220"></a>00220             <span class="comment">// After adding sub-directories from the directory and all sub-directories, </span>
<a name="l00221"></a>00221             <span class="comment">// return the list of sub-directories.</span>
<a name="l00222"></a>00222             <span class="keywordflow">return</span> <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.subDirectoriesInDirectory;
<a name="l00223"></a>00223         }
<a name="l00224"></a>00224 
<a name="l00233"></a>00233         <span class="keyword">private</span> <span class="keyword">static</span> <span class="keywordtype">void</span> GetAllSubDirectoriesInDirectoryInternal(<span class="keywordtype">string</span> directoryPath, <span class="keywordtype">int</span> maxSubDirectories)
<a name="l00234"></a>00234         {
<a name="l00235"></a>00235             <span class="comment">// Get the filesystem and security properties of the root directory.</span>
<a name="l00236"></a>00236             DirectoryInfo     directoryInfo        = <span class="keyword">new</span> DirectoryInfo(directoryPath);
<a name="l00237"></a>00237             DirectorySecurity directoryPermissions = <span class="keyword">new</span> DirectorySecurity();
<a name="l00238"></a>00238 
<a name="l00239"></a>00239             <span class="keywordflow">try</span>
<a name="l00240"></a>00240             {
<a name="l00241"></a>00241                 <span class="comment">// Check if the root directory is accessible.</span>
<a name="l00242"></a>00242                 directoryPermissions = Directory.GetAccessControl(directoryPath);
<a name="l00243"></a>00243 
<a name="l00244"></a>00244                 <span class="comment">// Check if the root directory is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00245"></a>00245                 <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00246"></a>00246                 {
<a name="l00247"></a>00247                     <span class="keywordflow">if</span> (<a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.subDirectoriesInDirectory.Count &lt; maxSubDirectories)
<a name="l00248"></a>00248                     {
<a name="l00249"></a>00249                         <span class="keywordflow">try</span>
<a name="l00250"></a>00250                         {
<a name="l00251"></a>00251                             <span class="comment">// Check if the directory is a real directory or if it is a Junction/Reparse point.</span>
<a name="l00252"></a>00252                             <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00253"></a>00253                             {
<a name="l00254"></a>00254                                 <span class="comment">// Add the directory to the final list of directory we will return.</span>
<a name="l00255"></a>00255                                 <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.subDirectoriesInDirectory.Add(directoryInfo.FullName);
<a name="l00256"></a>00256                             }
<a name="l00257"></a>00257                         }
<a name="l00258"></a>00258                         <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00259"></a>00259                         {
<a name="l00260"></a>00260                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00261"></a>00261                         }
<a name="l00262"></a>00262                         <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00263"></a>00263                         {
<a name="l00264"></a>00264                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00265"></a>00265                         }
<a name="l00266"></a>00266                         <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00267"></a>00267                         {
<a name="l00268"></a>00268                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00269"></a>00269                         }
<a name="l00270"></a>00270                         <span class="keywordflow">catch</span> (Exception)
<a name="l00271"></a>00271                         {
<a name="l00272"></a>00272                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00273"></a>00273                         }
<a name="l00274"></a>00274                     }
<a name="l00275"></a>00275                 }
<a name="l00276"></a>00276 
<a name="l00277"></a>00277                 <span class="comment">// Check if the folder is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00278"></a>00278                 <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00279"></a>00279                 {
<a name="l00280"></a>00280                     <span class="comment">// Get a list of all sub directories in the root directory.</span>
<a name="l00281"></a>00281                     <span class="keywordtype">string</span>[] subDirectories = Directory.GetDirectories(directoryPath, <span class="stringliteral">&quot;*&quot;</span>, SearchOption.TopDirectoryOnly);
<a name="l00282"></a>00282 
<a name="l00283"></a>00283                     <span class="comment">// Check each sub directory.</span>
<a name="l00284"></a>00284                     <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> subDirectory <span class="keywordflow">in</span> subDirectories)
<a name="l00285"></a>00285                     {
<a name="l00286"></a>00286                         <span class="comment">// Get the filesystem and security properties of the sub directories.</span>
<a name="l00287"></a>00287                         DirectoryInfo     subDirectoryInfo        = <span class="keyword">new</span> DirectoryInfo(subDirectory);
<a name="l00288"></a>00288                         DirectorySecurity subDirectoryPermissions = <span class="keyword">new</span> DirectorySecurity();
<a name="l00289"></a>00289 
<a name="l00290"></a>00290                         <span class="keywordflow">try</span>
<a name="l00291"></a>00291                         {
<a name="l00292"></a>00292                             <span class="comment">// Check if the sub directories are accessible.</span>
<a name="l00293"></a>00293                             subDirectoryPermissions = Directory.GetAccessControl(subDirectory);
<a name="l00294"></a>00294 
<a name="l00295"></a>00295                             <span class="comment">// Check if the folder is a real folder or if it is a Junction/Reparse point.</span>
<a name="l00296"></a>00296                             <span class="keywordflow">if</span> ((directoryInfo.Attributes &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
<a name="l00297"></a>00297                             {
<a name="l00298"></a>00298                                 <span class="comment">// Recursively check directories in each sub directory.</span>
<a name="l00299"></a>00299                                 DirectoryManagement.GetAllSubDirectoriesInDirectoryInternal(subDirectory, maxSubDirectories);
<a name="l00300"></a>00300                             }
<a name="l00301"></a>00301                         }
<a name="l00302"></a>00302                         <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00303"></a>00303                         {
<a name="l00304"></a>00304                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00305"></a>00305                         }
<a name="l00306"></a>00306                         <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00307"></a>00307                         {
<a name="l00308"></a>00308                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00309"></a>00309                         }
<a name="l00310"></a>00310                         <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00311"></a>00311                         {
<a name="l00312"></a>00312                             <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00313"></a>00313                         }
<a name="l00314"></a>00314                     }
<a name="l00315"></a>00315                 }
<a name="l00316"></a>00316             }
<a name="l00317"></a>00317             <span class="keywordflow">catch</span> (UnauthorizedAccessException)
<a name="l00318"></a>00318             {
<a name="l00319"></a>00319                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00320"></a>00320             }
<a name="l00321"></a>00321             <span class="keywordflow">catch</span> (InvalidOperationException)
<a name="l00322"></a>00322             {
<a name="l00323"></a>00323                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00324"></a>00324             }
<a name="l00325"></a>00325             <span class="keywordflow">catch</span> (PathTooLongException)
<a name="l00326"></a>00326             {
<a name="l00327"></a>00327                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00328"></a>00328             }
<a name="l00329"></a>00329             <span class="keywordflow">catch</span> (IOException)
<a name="l00330"></a>00330             {
<a name="l00331"></a>00331                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00332"></a>00332             }
<a name="l00333"></a>00333             <span class="keywordflow">catch</span> (Exception)
<a name="l00334"></a>00334             {
<a name="l00335"></a>00335                 <span class="comment">// Avoid application crashing because of unhandled exceptions.</span>
<a name="l00336"></a>00336             }
<a name="l00337"></a>00337         }
<a name="l00338"></a>00338 
<a name="l00343"></a>00343         <span class="keyword">private</span> <span class="keyword">static</span> List&lt;string&gt; GetPossibleDriveLetters()
<a name="l00344"></a>00344         {
<a name="l00345"></a>00345             <span class="comment">// Make a list of possibly valid Windows Drive Letters.</span>
<a name="l00346"></a>00346             List&lt;string&gt; possibleDriveLetters = <span class="keyword">new</span> List&lt;string&gt;() 
<a name="l00347"></a>00347             { 
<a name="l00348"></a>00348                 <span class="stringliteral">&quot;A&quot;</span>, <span class="stringliteral">&quot;B&quot;</span>, <span class="stringliteral">&quot;C&quot;</span>, <span class="stringliteral">&quot;D&quot;</span>, <span class="stringliteral">&quot;E&quot;</span>, <span class="stringliteral">&quot;F&quot;</span>, <span class="stringliteral">&quot;G&quot;</span>, <span class="stringliteral">&quot;H&quot;</span>, <span class="stringliteral">&quot;I&quot;</span>, <span class="stringliteral">&quot;J&quot;</span>, <span class="stringliteral">&quot;K&quot;</span>, <span class="stringliteral">&quot;L&quot;</span>, <span class="stringliteral">&quot;M&quot;</span>,
<a name="l00349"></a>00349                 <span class="stringliteral">&quot;N&quot;</span>, <span class="stringliteral">&quot;O&quot;</span>, <span class="stringliteral">&quot;P&quot;</span>, <span class="stringliteral">&quot;Q&quot;</span>, <span class="stringliteral">&quot;R&quot;</span>, <span class="stringliteral">&quot;S&quot;</span>, <span class="stringliteral">&quot;T&quot;</span>, <span class="stringliteral">&quot;U&quot;</span>, <span class="stringliteral">&quot;V&quot;</span>, <span class="stringliteral">&quot;W&quot;</span>, <span class="stringliteral">&quot;X&quot;</span>, <span class="stringliteral">&quot;Y&quot;</span>, <span class="stringliteral">&quot;Z&quot;</span>
<a name="l00350"></a>00350             };
<a name="l00351"></a>00351 
<a name="l00352"></a>00352             <span class="comment">// Return a string List of possibly valid Windows Drive Letters.</span>
<a name="l00353"></a>00353             <span class="keywordflow">return</span> possibleDriveLetters;
<a name="l00354"></a>00354         }
<a name="l00355"></a>00355 
<a name="l00360"></a><a class="code" href="a00002.html#a95c2b58d0f42c83f577e247e0d5af30b">00360</a>         <span class="keyword">public</span> <span class="keyword">static</span> List&lt;string&gt; <a class="code" href="a00002.html#a95c2b58d0f42c83f577e247e0d5af30b" title="Returns a string list of network shares in current computer&#39;s network/workgroup.">GetWindowsNetworkShares</a>()
<a name="l00361"></a>00361         {
<a name="l00362"></a>00362             <span class="comment">// Main variables.</span>
<a name="l00363"></a>00363             List&lt;string&gt; networkShares     = <span class="keyword">new</span> List&lt;string&gt;() { };
<a name="l00364"></a>00364             <span class="keywordtype">string</span>       netDomainsOutFile = <span class="stringliteral">@&quot;data\NetDomains.txt&quot;</span>;
<a name="l00365"></a>00365             <span class="keywordtype">string</span>       netDomainsResult  = <span class="stringliteral">@&quot;&quot;</span>;
<a name="l00366"></a>00366             <span class="keywordtype">string</span>       netServersOutFile = <span class="stringliteral">@&quot;data\NetServers.txt&quot;</span>;
<a name="l00367"></a>00367             <span class="keywordtype">string</span>       netServersResult  = <span class="stringliteral">@&quot;&quot;</span>;
<a name="l00368"></a>00368             <span class="keywordtype">string</span>       netSharesOutFile  = <span class="stringliteral">@&quot;data\NetShares.txt&quot;</span>;
<a name="l00369"></a>00369             <span class="keywordtype">string</span>[]     netSharesResult;
<a name="l00370"></a>00370 
<a name="l00371"></a>00371             <span class="comment">// Run NET VIEW and write the result of all network domains to a text file.</span>
<a name="l00372"></a>00372             <a class="code" href="a00010.html" title="Custom methods for Process Operations.">ProcessManagement</a>.<a class="code" href="a00010.html#a14d7376155b0dc8eba8b3e3212f81a7f" title="      ">StartHiddenShellProcess</a>(<span class="stringliteral">@&quot;NET.exe&quot;</span>, <span class="stringliteral">@&quot;VIEW /DOMAIN&quot;</span>, <span class="keyword">true</span>, netDomainsOutFile);
<a name="l00373"></a>00373 
<a name="l00374"></a>00374             <span class="comment">// Wait before continuing.</span>
<a name="l00375"></a>00375             <span class="comment">//Thread.Sleep(500);</span>
<a name="l00376"></a>00376 
<a name="l00377"></a>00377             <span class="keywordflow">if</span> (File.Exists(netDomainsOutFile))
<a name="l00378"></a>00378             {
<a name="l00379"></a>00379                 <span class="comment">// Read the result into a text string.</span>
<a name="l00380"></a>00380                 netDomainsResult = File.ReadAllText(netDomainsOutFile);
<a name="l00381"></a>00381             
<a name="l00382"></a>00382                 <span class="comment">// Find all network domains in the text string using regular expression.</span>
<a name="l00383"></a>00383                 <span class="keywordtype">string</span>          networkDomainPattern = <span class="stringliteral">@&quot;(?&lt;networkDomain&gt;\S+)\s+&quot;</span>;
<a name="l00384"></a>00384                 MatchCollection networkDomainMatches = Regex.Matches(netDomainsResult, networkDomainPattern);
<a name="l00385"></a>00385             
<a name="l00386"></a>00386                 <span class="comment">// Iterate each network domain in the list.</span>
<a name="l00387"></a>00387                 <span class="keywordflow">foreach</span> (Match networkDomainMatch <span class="keywordflow">in</span> networkDomainMatches)
<a name="l00388"></a>00388                 {
<a name="l00389"></a>00389                     <span class="comment">// Extract the exact network domain name from each match.</span>
<a name="l00390"></a>00390                     <span class="comment">// Example: &quot;DOM123 &quot; =&gt; &quot;DOM123&quot;</span>
<a name="l00391"></a>00391                     <span class="keywordtype">string</span> networkDomain = Regex.Replace(networkDomainMatch.ToString(), networkDomainPattern, <span class="stringliteral">&quot;${networkDomain}&quot;</span>).Trim();
<a name="l00392"></a>00392                 
<a name="l00393"></a>00393                     <span class="comment">// Ignore default shares and descriptive text that resulted from the NET VIEW command.</span>
<a name="l00394"></a>00394                     <span class="keywordflow">if</span> (
<a name="l00395"></a>00395                         !String.IsNullOrEmpty(networkDomain) &amp;&amp;
<a name="l00396"></a>00396                         (networkDomain != <span class="stringliteral">@&quot;Domain&quot;</span>) &amp;&amp;
<a name="l00397"></a>00397                         (networkDomain != <span class="stringliteral">@&quot;The&quot;</span>) &amp;&amp;
<a name="l00398"></a>00398                         (networkDomain != <span class="stringliteral">@&quot;command&quot;</span>) &amp;&amp;
<a name="l00399"></a>00399                         (networkDomain != <span class="stringliteral">@&quot;completed&quot;</span>) &amp;&amp;
<a name="l00400"></a>00400                         (networkDomain != <span class="stringliteral">@&quot;successfully.&quot;</span>) &amp;&amp;
<a name="l00401"></a>00401                         (!networkDomain.Contains(<span class="stringliteral">@&quot;----------&quot;</span>))
<a name="l00402"></a>00402                     ) {
<a name="l00403"></a>00403                         <span class="comment">// Run NET VIEW and write the result of all network servers to a text file.</span>
<a name="l00404"></a>00404                         <a class="code" href="a00010.html" title="Custom methods for Process Operations.">ProcessManagement</a>.<a class="code" href="a00010.html#a14d7376155b0dc8eba8b3e3212f81a7f" title="      ">StartHiddenShellProcess</a>(<span class="stringliteral">@&quot;NET.exe&quot;</span>, String.Format(<span class="stringliteral">@&quot;VIEW /DOMAIN:{0}&quot;</span>, networkDomain), <span class="keyword">true</span>, netServersOutFile);
<a name="l00405"></a>00405 
<a name="l00406"></a>00406                         <span class="comment">// Wait before continuing.</span>
<a name="l00407"></a>00407                         <span class="comment">//Thread.Sleep(500);</span>
<a name="l00408"></a>00408 
<a name="l00409"></a>00409                         <span class="keywordflow">if</span> (File.Exists(netServersOutFile))
<a name="l00410"></a>00410                         {
<a name="l00411"></a>00411                             <span class="comment">// Read the result into a text string.</span>
<a name="l00412"></a>00412                             netServersResult = File.ReadAllText(netServersOutFile);
<a name="l00413"></a>00413 
<a name="l00414"></a>00414                             <span class="comment">// Find all network servers in the text string using regular expression.</span>
<a name="l00415"></a>00415                             <span class="keywordtype">string</span>          networkServerPattern = <span class="stringliteral">@&quot;(?&lt;networkServer&gt;\\\\\S+)\s+&quot;</span>;
<a name="l00416"></a>00416                             MatchCollection networkServerMatches = Regex.Matches(netServersResult, networkServerPattern);
<a name="l00417"></a>00417                     
<a name="l00418"></a>00418                             <span class="comment">// Iterate each network server in the list.</span>
<a name="l00419"></a>00419                             <span class="keywordflow">foreach</span> (Match networkServerMatch <span class="keywordflow">in</span> networkServerMatches)
<a name="l00420"></a>00420                             {
<a name="l00421"></a>00421                                 <span class="comment">// Extract the exact network server name from each match.</span>
<a name="l00422"></a>00422                                 <span class="comment">// Example: &quot;\\SERVER &quot; =&gt; &quot;\\SERVER&quot;</span>
<a name="l00423"></a>00423                                 <span class="keywordtype">string</span> networkServer = Regex.Replace(networkServerMatch.ToString(), networkServerPattern, <span class="stringliteral">&quot;${networkServer}&quot;</span>).Trim();
<a name="l00424"></a>00424 
<a name="l00425"></a>00425                                 <span class="comment">// Run NET VIEW and write the result of all network shares at the current server to a text file.</span>
<a name="l00426"></a>00426                                 <a class="code" href="a00010.html" title="Custom methods for Process Operations.">ProcessManagement</a>.<a class="code" href="a00010.html#a14d7376155b0dc8eba8b3e3212f81a7f" title="      ">StartHiddenShellProcess</a>(<span class="stringliteral">@&quot;NET.exe&quot;</span>, <span class="stringliteral">@&quot;VIEW &quot;</span> + networkServer + <span class="stringliteral">@&quot;&quot;</span>, <span class="keyword">true</span>, netSharesOutFile);
<a name="l00427"></a>00427 
<a name="l00428"></a>00428                                 <span class="comment">// Wait before continuing.</span>
<a name="l00429"></a>00429                                 <span class="comment">//Thread.Sleep(500);</span>
<a name="l00430"></a>00430 
<a name="l00431"></a>00431                                 <span class="keywordflow">if</span> (File.Exists(netSharesOutFile))
<a name="l00432"></a>00432                                 {
<a name="l00433"></a>00433                                     <span class="comment">// Read the result into a text string.</span>
<a name="l00434"></a>00434                                     netSharesResult = File.ReadAllLines(netSharesOutFile);
<a name="l00435"></a>00435 
<a name="l00436"></a>00436                                     <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> netShareResultLine <span class="keywordflow">in</span> netSharesResult)
<a name="l00437"></a>00437                                     {
<a name="l00438"></a>00438                                         <span class="comment">// Find all network shares at the current server in the text string using regular expression.</span>
<a name="l00439"></a>00439                                         <span class="keywordtype">string</span> networkSharesPattern = <span class="stringliteral">@&quot;(?&lt;networkShares&gt;\S+)\s+Disk&quot;</span>;
<a name="l00440"></a>00440                                         Match  networkSharesMatch   = Regex.Match(netShareResultLine, networkSharesPattern);
<a name="l00441"></a>00441 
<a name="l00442"></a>00442                                         <span class="comment">// Extract the exact network server name from each match.</span>
<a name="l00443"></a>00443                                         <span class="comment">// Example: &quot;Share &quot; =&gt; &quot;Share&quot;</span>
<a name="l00444"></a>00444                                         <span class="keywordtype">string</span> networkShareMatch = Regex.Replace(networkSharesMatch.ToString(), networkSharesPattern, <span class="stringliteral">&quot;${networkShares}&quot;</span>).Trim();
<a name="l00445"></a>00445 
<a name="l00446"></a>00446                                         <span class="comment">// Ignore default shares and descriptive text that resulted from the NET VIEW command.</span>
<a name="l00447"></a>00447                                         <span class="keywordflow">if</span> (
<a name="l00448"></a>00448                                             !String.IsNullOrEmpty(networkShareMatch) &amp;&amp;
<a name="l00449"></a>00449                                             (networkShareMatch != <span class="stringliteral">@&quot;NETLOGON&quot;</span>) &amp;&amp;
<a name="l00450"></a>00450                                             (networkShareMatch != <span class="stringliteral">@&quot;Share&quot;</span>) &amp;&amp;
<a name="l00451"></a>00451                                             (networkShareMatch != <span class="stringliteral">@&quot;Shared&quot;</span>) &amp;&amp;
<a name="l00452"></a>00452                                             (networkShareMatch != <span class="stringliteral">@&quot;System&quot;</span>) &amp;&amp;
<a name="l00453"></a>00453                                             (networkShareMatch != <span class="stringliteral">@&quot;SYSVOL&quot;</span>) &amp;&amp;
<a name="l00454"></a>00454                                             (networkShareMatch != <span class="stringliteral">@&quot;The&quot;</span>) &amp;&amp;
<a name="l00455"></a>00455                                             (networkShareMatch != <span class="stringliteral">@&quot;There&quot;</span>)
<a name="l00456"></a>00456                                         ) {
<a name="l00457"></a>00457                                             <span class="keywordtype">string</span> networkShare = <span class="stringliteral">@&quot;&quot;</span> + networkServer + <span class="stringliteral">@&quot;\&quot;</span> + networkShareMatch + <span class="stringliteral">@&quot;&quot;</span>;
<a name="l00458"></a>00458 
<a name="l00459"></a>00459                                             <span class="comment">// Add the network share to our list if it&#39;s valid.</span>
<a name="l00460"></a>00460                                             <span class="keywordflow">if</span> (!networkShares.Contains(networkShare))
<a name="l00461"></a>00461                                             {
<a name="l00462"></a>00462                                                 networkShares.Add(networkShare);
<a name="l00463"></a>00463                                             }
<a name="l00464"></a>00464                                         }
<a name="l00465"></a>00465                                     }
<a name="l00466"></a>00466                                 }
<a name="l00467"></a>00467                             }
<a name="l00468"></a>00468                         }
<a name="l00469"></a>00469                     }
<a name="l00470"></a>00470                 }
<a name="l00471"></a>00471             }
<a name="l00472"></a>00472             
<a name="l00473"></a>00473             <span class="comment">// Delete temporary data files.</span>
<a name="l00474"></a>00474             <span class="keywordflow">if</span> (File.Exists(netDomainsOutFile))
<a name="l00475"></a>00475             {
<a name="l00476"></a>00476                 File.Delete(netDomainsOutFile);
<a name="l00477"></a>00477             }
<a name="l00478"></a>00478             
<a name="l00479"></a>00479             <span class="keywordflow">if</span> (File.Exists(netDomainsOutFile))
<a name="l00480"></a>00480             {
<a name="l00481"></a>00481                 File.Delete(netServersOutFile);
<a name="l00482"></a>00482             }
<a name="l00483"></a>00483             
<a name="l00484"></a>00484             <span class="keywordflow">if</span> (File.Exists(netDomainsOutFile))
<a name="l00485"></a>00485             {
<a name="l00486"></a>00486                 File.Delete(netSharesOutFile);
<a name="l00487"></a>00487             }
<a name="l00488"></a>00488 
<a name="l00489"></a>00489             <span class="comment">// Return the list of network shares.</span>
<a name="l00490"></a>00490             <span class="keywordflow">return</span> networkShares;
<a name="l00491"></a>00491         }
<a name="l00492"></a>00492 
<a name="l00497"></a>00497         <span class="keyword">private</span> <span class="keyword">static</span> List&lt;string&gt; GetWindowsSystemDirectories()
<a name="l00498"></a>00498         {
<a name="l00499"></a>00499             <span class="comment">// Make a list of system directories.</span>
<a name="l00500"></a>00500             List&lt;string&gt; systemDirectories = <span class="keyword">new</span> List&lt;string&gt;() { 
<a name="l00501"></a>00501                 <span class="stringliteral">@&quot;$Recycle.Bin&quot;</span>, 
<a name="l00502"></a>00502                 <span class="stringliteral">@&quot;Config.Msi&quot;</span>, 
<a name="l00503"></a>00503                 <span class="stringliteral">@&quot;Documents and Settings&quot;</span>, 
<a name="l00504"></a>00504                 <span class="stringliteral">@&quot;MSOCache&quot;</span>, 
<a name="l00505"></a>00505                 <span class="stringliteral">@&quot;PerfLogs&quot;</span>, 
<a name="l00506"></a>00506                 <span class="stringliteral">@&quot;ProgramData&quot;</span>, 
<a name="l00507"></a>00507                 <span class="stringliteral">@&quot;Recovery&quot;</span>, 
<a name="l00508"></a>00508                 <span class="stringliteral">@&quot;System Volume Information&quot;</span>,
<a name="l00509"></a>00509                 <span class="stringliteral">@&quot;Application Data&quot;</span>,
<a name="l00510"></a>00510                 <span class="stringliteral">@&quot;Cookies&quot;</span>, 
<a name="l00511"></a>00511                 <span class="stringliteral">@&quot;Local Settings&quot;</span>, 
<a name="l00512"></a>00512                 <span class="stringliteral">@&quot;My Documents&quot;</span>, 
<a name="l00513"></a>00513                 <span class="stringliteral">@&quot;My Music&quot;</span>, 
<a name="l00514"></a>00514                 <span class="stringliteral">@&quot;My Pictures&quot;</span>, 
<a name="l00515"></a>00515                 <span class="stringliteral">@&quot;My Videos&quot;</span>, 
<a name="l00516"></a>00516                 <span class="stringliteral">@&quot;NetHood&quot;</span>, 
<a name="l00517"></a>00517                 <span class="stringliteral">@&quot;PrintHood&quot;</span>, 
<a name="l00518"></a>00518                 <span class="stringliteral">@&quot;SendTo&quot;</span>, 
<a name="l00519"></a>00519                 <span class="stringliteral">@&quot;Start Menu&quot;</span>, 
<a name="l00520"></a>00520                 <span class="stringliteral">@&quot;Templates&quot;</span>
<a name="l00521"></a>00521             };
<a name="l00522"></a>00522 
<a name="l00523"></a>00523             <span class="comment">// Return the list of system directories.</span>
<a name="l00524"></a>00524             <span class="keywordflow">return</span> systemDirectories;
<a name="l00525"></a>00525         }
<a name="l00526"></a>00526 
<a name="l00532"></a><a class="code" href="a00002.html#a84b22846ab7a40750701cf1e5e948199">00532</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="a00002.html#a84b22846ab7a40750701cf1e5e948199" title="Checks if the directory is a Windows system directory.">IsWindowsSystemDirectory</a>(<span class="keywordtype">string</span> directoryPath)
<a name="l00533"></a>00533         {
<a name="l00534"></a>00534             <span class="comment">// Main variables.</span>
<a name="l00535"></a>00535             <span class="keywordtype">bool</span> directoryIsSystemDirectory = <span class="keyword">false</span>;
<a name="l00536"></a>00536             List&lt;string&gt; systemDirectories = <span class="keyword">new</span> List&lt;string&gt;() { };
<a name="l00537"></a>00537 
<a name="l00538"></a>00538             <span class="comment">// Get a string List of possibly valid Windows Drive Letters.</span>
<a name="l00539"></a>00539             List&lt;string&gt; PossibleDriveLetters = <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.GetPossibleDriveLetters();
<a name="l00540"></a>00540 
<a name="l00541"></a>00541             <span class="comment">// Make a list of system directories in the local windows file system that can throw I/O errors.</span>
<a name="l00542"></a>00542             systemDirectories = <a class="code" href="a00002.html" title="Custom methods for Directory Operations.">DirectoryManagement</a>.GetWindowsSystemDirectories();
<a name="l00543"></a>00543 
<a name="l00544"></a>00544             <span class="comment">// Check if the directory is a Windows system directory.</span>
<a name="l00545"></a>00545             <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> systemDirectory <span class="keywordflow">in</span> systemDirectories)
<a name="l00546"></a>00546             {
<a name="l00547"></a>00547                 <span class="keywordflow">foreach</span> (<span class="keywordtype">string</span> driveLetter <span class="keywordflow">in</span> PossibleDriveLetters)
<a name="l00548"></a>00548                 {
<a name="l00549"></a>00549                     <span class="comment">// Check the directory against all possible windows drive letters.</span>
<a name="l00550"></a>00550                     <span class="keywordflow">if</span> ((driveLetter + <span class="stringliteral">@&quot;:\\&quot;</span> + systemDirectory).ToLower() == directoryPath.ToLower())
<a name="l00551"></a>00551                     {
<a name="l00552"></a>00552                         directoryIsSystemDirectory = <span class="keyword">true</span>;
<a name="l00553"></a>00553                     }
<a name="l00554"></a>00554                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> ((driveLetter + <span class="stringliteral">@&quot;:\&quot;</span> + systemDirectory).ToLower() == directoryPath.ToLower())
<a name="l00555"></a>00555                     {
<a name="l00556"></a>00556                         directoryIsSystemDirectory = <span class="keyword">true</span>;
<a name="l00557"></a>00557                     }
<a name="l00558"></a>00558                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Regex.IsMatch(directoryPath, <span class="stringliteral">@&quot;\w:\W+Users\W+(\S|\s)+\W+&quot;</span> + systemDirectory))
<a name="l00559"></a>00559                     {
<a name="l00560"></a>00560                         directoryIsSystemDirectory = <span class="keyword">true</span>;
<a name="l00561"></a>00561                     }
<a name="l00562"></a>00562                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Regex.IsMatch(directoryPath, <span class="stringliteral">@&quot;\w:\W+Users\W+(\S|\s)+\W+Documents\W+&quot;</span> + systemDirectory))
<a name="l00563"></a>00563                     {
<a name="l00564"></a>00564                         directoryIsSystemDirectory = <span class="keyword">true</span>;
<a name="l00565"></a>00565                     }
<a name="l00566"></a>00566                 }
<a name="l00567"></a>00567             }
<a name="l00568"></a>00568 
<a name="l00569"></a>00569             <span class="comment">// Return the Boolean.</span>
<a name="l00570"></a>00570             <span class="keywordflow">return</span> directoryIsSystemDirectory;
<a name="l00571"></a>00571         }
<a name="l00572"></a>00572 
<a name="l00580"></a><a class="code" href="a00002.html#aa8a5138729250fc00ca5b9906ce3bfae">00580</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">string</span> <a class="code" href="a00002.html#aa8a5138729250fc00ca5b9906ce3bfae" title="Returns the path from where current code is called from after it has been compiled and deployed...">GetRuntimeExecutingPath</a>()
<a name="l00581"></a>00581         {
<a name="l00582"></a>00582             <span class="comment">// Main variables.</span>
<a name="l00583"></a>00583             <span class="keywordtype">string</span> runtimeExecutingPath = <span class="stringliteral">@&quot;&quot;</span>;
<a name="l00584"></a>00584 
<a name="l00585"></a>00585             <span class="comment">// Get the current runtime executing path.</span>
<a name="l00586"></a>00586             runtimeExecutingPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
<a name="l00587"></a>00587 
<a name="l00588"></a>00588             <span class="comment">// Return the Runtime Executing Path.</span>
<a name="l00589"></a>00589             <span class="keywordflow">if</span> (runtimeExecutingPath.IndexOf(<span class="stringliteral">@&quot;\htdocs\cgi-bin&quot;</span>) &gt;= 0)
<a name="l00590"></a>00590             {
<a name="l00591"></a>00591                 <span class="keywordflow">return</span> runtimeExecutingPath.Substring(6, runtimeExecutingPath.IndexOf(<span class="stringliteral">@&quot;\htdocs\cgi-bin&quot;</span>) - 6);
<a name="l00592"></a>00592             }
<a name="l00593"></a>00593             <span class="keywordflow">else</span>
<a name="l00594"></a>00594             {
<a name="l00595"></a>00595                 <span class="keywordflow">return</span> runtimeExecutingPath.Substring(6);
<a name="l00596"></a>00596             }
<a name="l00597"></a>00597         }
<a name="l00598"></a>00598 
<a name="l00599"></a>00599     }
<a name="l00600"></a>00600 
<a name="l00604"></a><a class="code" href="a00010.html">00604</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="a00010.html" title="Custom methods for Process Operations.">ProcessManagement</a>
<a name="l00605"></a>00605     {
<a name="l00610"></a><a class="code" href="a00010.html#a14d7376155b0dc8eba8b3e3212f81a7f">00610</a>         <span class="keyword">public</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00010.html#a14d7376155b0dc8eba8b3e3212f81a7f" title="      ">StartHiddenShellProcess</a>(<span class="keywordtype">string</span> processExecutable, <span class="keywordtype">string</span> argumentsString = <span class="stringliteral">@&quot;&quot;</span>, <span class="keywordtype">bool</span> outputToFile = <span class="keyword">false</span>, <span class="keywordtype">string</span> fileNameAndPath = <span class="stringliteral">@&quot;&quot;</span>)
<a name="l00611"></a>00611         {
<a name="l00612"></a>00612             <span class="comment">// Prepare to run a hidden shell process in the background.</span>
<a name="l00613"></a>00613             ProcessStartInfo process = <span class="keyword">new</span> ProcessStartInfo(processExecutable);
<a name="l00614"></a>00614             process.Arguments        = argumentsString;
<a name="l00615"></a>00615             process.UseShellExecute  = <span class="keyword">true</span>;
<a name="l00616"></a>00616             process.CreateNoWindow   = <span class="keyword">true</span>;
<a name="l00617"></a>00617             process.WindowStyle      = ProcessWindowStyle.Hidden;
<a name="l00618"></a>00618 
<a name="l00619"></a>00619             <span class="keywordflow">if</span> (outputToFile &amp;&amp; !String.IsNullOrEmpty(fileNameAndPath))
<a name="l00620"></a>00620             {
<a name="l00621"></a>00621                 <span class="comment">// Make Output Redirection possible.</span>
<a name="l00622"></a>00622                 process.UseShellExecute        = <span class="keyword">false</span>;
<a name="l00623"></a>00623                 process.RedirectStandardOutput = <span class="keyword">true</span>;
<a name="l00624"></a>00624 
<a name="l00625"></a>00625                 <span class="comment">// Run the process and write the output to the inputted file.</span>
<a name="l00626"></a>00626                 File.WriteAllText(fileNameAndPath, Process.Start(process).StandardOutput.ReadToEnd());
<a name="l00627"></a>00627             }
<a name="l00628"></a>00628             <span class="keywordflow">else</span>
<a name="l00629"></a>00629             {
<a name="l00630"></a>00630                 <span class="comment">// Run the process.</span>
<a name="l00631"></a>00631                 Process.Start(process);
<a name="l00632"></a>00632             }
<a name="l00633"></a>00633         }
<a name="l00634"></a>00634 
<a name="l00635"></a>00635     }
<a name="l00636"></a>00636 
<a name="l00637"></a>00637 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="a00014.html">FileSystem.cs</a>      </li>

    <li class="footer">Generated on Thu Jan 10 2013 07:05:17 for Voya Media by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
